package com.dyz.LeetCodeforSwordFingerOffer;

/**
 * @ClassNamereplaceSpace05
 * @Description
 * @Author: daiyizheng
 * @Date2021/6/13 4:08 下午
 * @Version V1.0
 **/
public class replaceSpace05 {
    public String replaceSpace(String s) {
        if (s==null || s.length()==0){
            return s;
        }

        //使用StrinBuilder
        StringBuilder ans = new StringBuilder();
        for (int i=0; i<s.length();i++){
            if(s.charAt(i)==' '){
                ans.append("%20");
            }else{
                ans.append(s.charAt(i));
            }
        }
        return ans.toString();
    }
}
